#pragma once

#include "constants.h"
#include "effecthandler.h"

#define MAX_CHAT_LENGTH 128
#define MAX_CHAT_LINES 6

class Sprite;
class PlayField;

struct PlayerInfo
{
	char name[64];
	int fieldNum;
	bool dead;
	int place;
	int level;
	int wins;
	bool ready;
	bool connected;
	bool typing;
};

#define PLAYFIELD_OFFSET_X 8
#define PLAYFIELD_OFFSET_Y 8

void irqHBlank();

class FieldGraphics
{
public:
	static void InitGraphics();

	FieldGraphics();
	virtual ~FieldGraphics();

	int GetFieldX(int fieldNum) const {
		return PLAYFIELD_OFFSET_X + (fieldNum % 6) * BLOCKSIZE;
	}
	int GetFieldY(int fieldNum, bool scrolled = false) const {
		int scroll = scrolled ? scrollOffset : 0;
		return PLAYFIELD_OFFSET_Y + (fieldNum / 6 - PF_FIRST_VISIBLE_ROW) * BLOCKSIZE + scroll;
	}

	void Draw(PlayField *pf);
	void DrawField(PlayField *pf);
	void DrawMarkers(PlayField *pf);
	void DrawEffects() { effects.Draw(); };
		
	void PrintCountdown(int count);

	EffectHandler *GetEffectHandler() { return &effects; }

protected:
	void PrintScore(int score);
	void PrintTime(int ticks);
	void PrintStopTime(int ticks);

	void PrintSmall(uint32_t offset, const char* text);
	void PrintLarge(uint32_t offset, const char* text);
	
	int LargeCharTile(char c);
	int SmallCharTile(char c);

	EffectHandler effects;
	Sprite* marker;
	int scrollOffset;

	friend void irqHBlank();
};

extern FieldGraphics* g_fieldGraphics;
